package com.example.car.controller;

import com.example.car.entity.Driver;
import com.example.car.model.IdNameModel;
import com.example.car.service.DriverService;
import com.example.car.vo.CommonResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("driver")
public class DriverController {

    @Autowired
    private DriverService driverService;

    @Autowired
    private MongoTemplate mongoTemplate;

    @GetMapping("checkBoxlist")
    @ApiOperation("司机信息下拉框")
    public CommonResult getDriverList() {
        List<Driver> list = driverService.getDriverList();

        List<IdNameModel> collect = list.stream().map(item -> {
            IdNameModel idNameModel = new IdNameModel();
            BeanUtils.copyProperties(item, idNameModel);
            return idNameModel;
        }).collect(Collectors.toList());

        return CommonResult.success().data("data", collect);
    }

    @GetMapping("info/{driverId}")
    @ApiOperation("司机信息")
    public CommonResult getDriverInfo(@PathVariable("driverId") String driverId) {
        Driver driver = driverService.getDriverInfo(driverId);
        return CommonResult.success().data("data", driver);
    }

}
